import {BasicColumn, FormSchema} from '/@/components/Table';
import {rules} from '/@/utils/helper/validator';
import {render} from '/@/utils/common/renderUtils';
import {UploadBizType} from '/@/enums/uploadEnum';
import {DescItem} from '/@/components/Description/index';

export const columns: BasicColumn[] = [
  {
    title: '会员等级',
    dataIndex: 'weight',
    width: 80,
    slot: 'levelWeight'
  },
  {
    title: '等级名称',
    dataIndex: 'name',
    width: 100,
  },
  {
    title: '等级权益',
    dataIndex: 'equity',
    width: 200,
    slot: 'equity'
  },
  {
    title: '等级礼包',
    dataIndex: 'levelPack',
    width: 200,
    slot: 'levelPack'
  },
  {
    title: '会员人数',
    dataIndex: 'memberNum',
    width: 80,
  },
  {
    title: '默认',
    dataIndex: 'isDefault',
    customRender: ({text}) => {
      let color = text ? 'blue' : 'green'
      return render.renderTag(text ? '是' : '否', color)
    },
    width: 45,
  },
  {
    title: '状态',
    dataIndex: 'status',
    customRender: ({text}) => {
      let color = 'green'
      if (text === '0') {
        color = 'red'
      }
      return render.renderTag(render.renderDict(text, 'data_use_status'), color)
    },
    width: 60,
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '等级名称',
    field: 'name',
    component: 'Input',
  }
];

export const formSchema: FormSchema[] = [
  {
    label: '基础信息',
    field: 'baseInfo',
    component: 'Divider',
  },
  
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
  {
    label: '等级名称',
    field: 'name',
    required: true,
    component: 'Input',
  },
  {
    label: '等级权重',
    field: 'weight',
    required: true,
    component: 'JDictSelectTag',
    componentProps: {
      showSearch: true,
      dictCode: 'member_level_weight',
      placeholder: '请选择',
    },
  },
  {
    label: '背景图',
    field: 'backgroundUrl',
    component: 'JImageUpload',
    componentProps: {
      fileMax:1,
      bizType: UploadBizType.GENERAL_IMAGE
    },
  },

  {
    label: '升级条件',
    field: 'upgrade',
    helpMessage: '用户的实际消费金额满足后，自动升级',
    component: 'Input',
    slot: 'upgrade'
  },

  

  {
    field: 'isDefault',
    label: '默认',
    component: 'RadioGroup',
    helpMessage: '新注册的会员将采用默认等级',
    defaultValue: false,
    componentProps: {
      options: [
        {
          label: '是',
          value: true,
        },
        {
          label: '否',
          value: false,
        },
      ],
    },
  },
  {
    label: '状态',
    field: 'status',
    required: true,
    component: 'JDictSelectTag',
    ifShow: ({ model, field }) => model['isDefault'] === 0, 
    defaultValue: '1',
    componentProps: {
      showSearch: true,
      type: "radio",
      dictCode: 'data_use_status',
      placeholder: '请选择',
    },
  },

  {
    label: '等级说明',
    field: 'remark',
    component: 'InputTextArea',
    componentProps: {
      autoSize: {
        minRows: 6,
        maxRows: 12
      }
    }
  },

  {
    label: '等级权益',
    field: 'equity',
    component: 'Divider',
  },
  

  // 消费折扣权益,  0: 不打折, 9.8代表98折
  {
    label: '消费折扣',
    field: 'equityConsumeDiscount',
    component: 'Input',
    required: true,
    helpMessage: [
      "折扣率范围0.0-9.9，例如: 9.8代表98折，0代表不折扣",
    ],
    slot: 'equityConsumeDiscount'
  },
  
  // 积分回馈倍率权益, 回馈积分 = 消费金额 * 积分回馈倍率
  {
    label: '积分回馈倍率',
    field: 'equityPointFeedback',
    required: true,
    helpMessage: [
      "回馈积分 = 消费金额 * 积分回馈倍率",
    ],
    component: 'Input',
    slot: 'equityPointFeedback'
  },

  {
    label: '等级礼包',
    field: 'pack',
    component: 'Divider',
  },

  {
    label: '赠送积分',
    field: 'sendPoint',
    component: 'Input',
  },
  {
    label: '赠送红包',
    field: 'sendBalance',
    component: 'InputNumber',
    componentProps: {
      precision: 1
    }
  },

];

export const formPasswordSchema: FormSchema[] = [
  {
    label: '用户账号',
    field: 'userName',
    component: 'Input',
    componentProps: {readonly: true}
  },
  {
    label: '',
    field: 'id',
    show: false,
    component: 'Input'
  },
  {
    label: '登录密码',
    field: 'password',
    component: 'StrengthMeter',
    componentProps: {
      placeholder: '请输入登录密码',
    },
    rules: [
      {
        required: true,
        message: '请输入登录密码',
      },
    ],
  },
  {
    label: '确认密码',
    field: 'confirmPassword',
    component: 'InputPassword',
    dynamicRules: ({values}) => rules.confirmPassword(values,true)
  }
];


/**
 * 搜索用户
 */
export const searchUserFormSchema: FormSchema[] = [
  {
    field: 'userName',
    label: '用户账号',
    component: 'Input',
    colProps: { span: 12 },
  },
  {
    field: 'test',
    label: '',
    component: 'Input',
    slot: 'addUser',
    colProps: { span: 12 },
  },

];


/**
 * 用户基本信息
 */
export const baseInfoDescSchema: DescItem[] = [
  {
    field: 'userName',
    label: '用户名',
    span: 2,
  },
  {
    field: 'nickName',
    label: '昵称',
    span: 2,
  },
  {
    field: 'phone',
    label: '联系电话',
    span: 2,
  },
  {
    field: 'email',
    label: '邮箱',
    span: 2,
  },
  {
    field: 'registerIp',
    label: '注册IP',
    span: 2,
  },
  {
    field: 'registerTerminal',
    label: '注册终端',
    span: 2,
    render: (curVal, data) => {
      return render.renderDict(curVal, 'terminal');
    },
  },
  {
    field: 'sex',
    label: '性别',
    span: 2,
    render: (curVal, data) => {
      return render.renderDict(curVal, 'sys_user_sex');
    },
  },

  {
    field: 'birthday',
    label: '生日',
    span: 2,
  },
  {
    field: 'lastLoginDate',
    label: '最后登录时间',
    span: 4,
  },
  {
    field: 'lastLoginIp',
    label: '最后登录IP',
    span: 4,
  },
  
  {
    field: 'address',
    label: '地址',
    span: 4,
    render: (curVal, data) => {
      return curVal && curVal !== '' ? `${data.fullAddress}-${curVal}` : data.fullAddress;
    },
  },
]

/**
 * 用户权益信息
 */

export const quityInfoDescSchema: DescItem[] = [
  {
    field: 'point',
    label: '积分',
    span: 2,
  },
]
